int copy(char *read_dir_path, char *write_dir_path)  
{  
    DIR * p_dir;  
    struct dirent * p_dirent;  
  
      
    char read_buf[256];  
    char write_buf[256];  
  
    sprintf(read_buf,"%s/", read_dir_path);  
    sprintf(write_buf,"%s/",write_dir_path);  
  
    strcat(read_dir_path,"/");  
    if( Is_dir(read_buf) )  
    {  
        //mkdir   
        if(mkdir(write_buf, 0755) < 0)  
        {  
            printf("mkdir fall:%s\n", strerror(errno));  
            return -1;  
        }  
  
  
        //opendir and readdir   
  
        if((p_dir = opendir(read_buf)) == NULL )  
        {  
            printf("Usage:cp -r <src_dir> <dat_dir> error:%s\n",strerror(errno));  
            return -1;  
        }  
  
        while((p_dirent=readdir(p_dir)) != NULL)  
        {  
            char read_buffer[256];  
            char write_buffer[256];  
            sprintf(read_buffer,"%s%s", read_buf, p_dirent->d_name);  
            sprintf(write_buffer,"%s%s", write_buf, p_dirent->d_name);  
  
            printf("%s\n%s\n",read_buffer,write_buffer);  
  
            //it is a directory   
            if( Is_dir(read_buffer) && 0 != strcmp(p_dirent->d_name, ".") && 0 != strcmp(p_dirent->d_name, "..") )  
            {  
                  
                copy_r(read_buffer, write_buffer);  
            }  
  
            else if(0 != strcmp(p_dirent->d_name, ".") && 0 != strcmp(p_dirent->d_name, ".."))  
            {  
                //copy file   
                if( file_copy_line(read_buffer, write_buffer) < 0 )  
                    return 0;  
            }  
  
  
        }  
  
        closedir(p_dir);  
  
    }  

}